//
//  CommonModel.m
//  ICrEAM
//
//  Created by mac on 16/10/28.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "CommonModel.h"
#import <objc/runtime.h>
@implementation CommonModel
-(void)encodeWithCoder:(NSCoder *)aCoder{
    unsigned count;
    objc_property_t *propertys= class_copyPropertyList([self class], &count);
    for (int i=0; i<count; i++) {
        objc_property_t property=propertys[i];
        NSString *key=[NSString stringWithUTF8String:property_getName(property)];
        [aCoder encodeObject:[self valueForKey:key] forKey:key];
    }
    free(propertys);

    
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self=[super init];
    if (self) {
        unsigned count;
        objc_property_t *propertys= class_copyPropertyList([self class], &count);
        for (int i=0; i<count; i++) {
            objc_property_t property=propertys[i];
            NSString *key=[NSString stringWithUTF8String:property_getName(property)];
            [self setValue:[aDecoder decodeObjectForKey:key] forKey:key];
        }
        free(propertys);
    }
    return self;
}
-(id)copyWithZone:(NSZone *)zone{
    CommonModel *model =[[self class]allocWithZone:zone];
    
    return model;
    
}
@end
